package mdm.led.util;

import org.apache.commons.lang3.time.DateUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

public class DateUtil {
    public static String addDate(String date, Integer amount) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return simpleDateFormat.format(DateUtils.addDays(simpleDateFormat.parse(date), amount));
    }

    public static String formatDate(Date date) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return simpleDateFormat.format(date);
    }
    
    
    public static String formatDateTime(Date date) throws Exception {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(date);
    }
    
    /**
     * jlq
     * @param str
     * @return
     * @throws Exception
     */
    public static String formatDate(String str) throws Exception {
    	if(str!=null && !str.equals("")) {
    		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(str);
            return simpleDateFormat.format(date);
    	}
        return "";
    }
    
    public static String formatDateTime(String str) throws Exception {
    	if(str!=null && !str.equals("")) {
    		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    		Date date = simpleDateFormat.parse(str);
    		return simpleDateFormat.format(date);
    	}
    	return "";
    }
}
